// 深度拷贝
export function DeepCopy(data) {
  if (typeof data === 'undefined') {
    return undefined
  }
  if (data === null) {
    return null
  }
  if (data.constructor !== Array && data.constructor !== Object) {
    return data
  }
  if (data.constructor === Array) {
    let arr = []
    data.forEach(item => {
      arr.push(DeepCopy(item))
    })
    return arr
  }
  if (data.constructor === Object) {
    let obj = {}
    for (let key in data) {
      obj[key] = DeepCopy(data[key])
    }
    return obj
  }
}

export function JSONCopy(data) {
  return JSON.parse(JSON.stringify(data))
}
// router 改装为可以没有菜单单独访问的路由
import Home from '../home.vue'
export function getRouter(r) {
  return [
    {
      path: '/home',
      name: 'home',
      component: Home,
      children: DeepCopy(r).map(item => {
        item.path = item.path.match(/\w+/)[0]
        item.name = 'child_' + item.name
        return item
      }),
    },
    ...r,
  ]
}
